﻿@using Abp.Authorization.Users
@using Abp.Configuration
@using Abp.Extensions
@using Abp.Zero.Configuration
@using MyCompanyName.AbpZeroTemplate.Web.Areas.Mpa.Models.Common.Modals
@model MyCompanyName.AbpZeroTemplate.Web.Areas.Mpa.Models.Users.CreateOrEditUserModalViewModel

@Html.Partial("~/Areas/Mpa/Views/Common/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel(Model.IsEditMode ? (L("EditUser") + ": " + Model.User.UserName) : L("CreateNewUser")))

<div class="modal-body">

    <div class="tabbable-line">
        <ul class="nav nav-tabs ">
            <li class="active">
                <a href="#UserInformationsTab" data-toggle="tab" aria-expanded="true">
                    @L("UserInformations")
                </a>
            </li>
            <li class="">
                <a href="#RolesTab" data-toggle="tab" aria-expanded="false">
                    @L("Roles") <b class="badge badge-primary"><span id="assigned-role-count">@Model.AssignedRoleCount</span></b>
                </a>
            </li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane active" id="UserInformationsTab">

                <form name="UserInformationsForm" role="form" novalidate class="form-validation">

                    @if (Model.IsEditMode)
                    {
                        <input type="hidden" name="Id" value="@Model.User.Id" />
                    }

                    <div class="row">
                        <div class="col-sm-4 text-center">
                            @if (Model.ProfilePictureId.HasValue)
                            {
                                <img src="@Url.Action("GetProfilePictureById", "Profile", new { area = string.Empty })?id=@(Model.ProfilePictureId.Value)" width="128" height="128" class="img-thumbnail img-rounded user-edit-dialog-profile-image" />
                            }
                            else
                            {
                                <img src="@Url.Content("~/Common/Images/default-profile-picture.png")" width="128" height="128" class="img-thumbnail img-rounded user-edit-dialog-profile-image" />
                            }
                        </div>
                        <div class="col-sm-8">
                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input class="form-control@(Model.User.Name.IsNullOrEmpty() ? "" : " edited")" value="@Model.User.Name" type="text" name="Name" required maxlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MaxNameLength">
                                <label>@L("Name")</label>
                            </div>

                            <div class="form-group form-md-line-input form-md-floating-label no-hint">
                                <input type="text" name="Surname" class="form-control@(Model.User.Surname.IsNullOrEmpty() ? "" : " edited")" value="@Model.User.Surname" required maxlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MaxSurnameLength">
                                <label>@L("Surname")</label>
                            </div>
                        </div>
                    </div>

                    <div class="form-group form-md-line-input form-md-floating-label no-hint">
                        <input type="email" name="EmailAddress" class="form-control@(Model.User.EmailAddress.IsNullOrEmpty() ? "" : " edited")" value="@Model.User.EmailAddress" required maxlength="@AbpUserBase.MaxEmailAddressLength">
                        <label>@L("EmailAddress")</label>
                    </div>

                    <div class="form-group form-md-line-input form-md-floating-label no-hint">
                        <input type="text" name="PhoneNumber" class="form-control@(Model.User.PhoneNumber.IsNullOrEmpty() ? "" : " edited")" value="@Model.User.PhoneNumber" maxlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MaxPhoneNumberLength">
                        <label>@L("PhoneNumber")</label>
                    </div>

                    <div class="form-group form-md-line-input form-md-floating-label">
                        <input type="text" @Html.Raw(!Model.CanChangeUserName ? "disabled=\"disabled\"" : "") name="UserName" class="form-control@(Model.User.EmailAddress.IsNullOrEmpty() ? "" : " edited")" value="@Model.User.UserName" required maxlength="@AbpUserBase.MaxUserNameLength">
                        <label>@L("UserName")</label>
                        @if (!Model.CanChangeUserName)
                        {
                            <span class="help-block">@L("CanNotChangeAdminUserName")</span>
                        }
                    </div>

                    <div class="md-checkbox-list">
                        <div class="md-checkbox">
                            <input id="EditUser_SetRandomPassword" class="md-check" type="checkbox" name="SetRandomPassword" value="true" @Html.Raw(Model.IsEditMode ? "" : "checked=\"checked\"") />
                            <label for="EditUser_SetRandomPassword">
                                <span class="inc"></span>
                                <span class="check"></span>
                                <span class="box"></span>
                                @L("SetRandomPassword")
                            </label>
                        </div>
                    </div>

                    <div class="form-group form-md-line-input form-md-floating-label no-hint" style="@(Model.IsEditMode ? "display:block" : "display:none")">
                        <input id="EditUser_Password" type="password" name="Password" class="form-control" maxlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MaxPlainPasswordLength" minlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MinPlainPasswordLength">
                        <label>@L("Password")</label>
                    </div>

                    <div class="form-group form-md-line-input form-md-floating-label no-hint" style="@(Model.IsEditMode ? "display:block" : "display:none")">
                        <input type="password" name="PasswordRepeat" class="form-control" maxlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MaxPlainPasswordLength" minlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MinPlainPasswordLength" equalto="#EditUser_Password">
                        <label>@L("PasswordRepeat")</label>
                    </div>

                    <div class="md-checkbox-list">
                        <div class="md-checkbox">
                            <input id="EditUser_ShouldChangePasswordOnNextLogin" class="md-check" type="checkbox" name="ShouldChangePasswordOnNextLogin" value="true" @Html.Raw(Model.User.ShouldChangePasswordOnNextLogin ? "checked=\"checked\"" : "")>
                            <label for="EditUser_ShouldChangePasswordOnNextLogin">
                                <span class="inc"></span>
                                <span class="check"></span>
                                <span class="box"></span>
                                @L("ShouldChangePasswordOnNextLogin")
                            </label>
                        </div>
                        <div class="md-checkbox">
                            <input id="EditUser_SendActivationEmail" class="md-check" type="checkbox" name="SendActivationEmail" value="true" @Html.Raw(Model.IsEditMode ? "" : "checked=\"checked\"")>
                            <label for="EditUser_SendActivationEmail">
                                <span class="inc"></span>
                                <span class="check"></span>
                                <span class="box"></span>
                                @L("SendActivationEmail")
                            </label>
                        </div>
                        <div class="md-checkbox">
                            <input id="EditUser_IsActive" class="md-check" type="checkbox" name="IsActive" value="true" @Html.Raw(Model.User.IsActive ? "checked=\"checked\"" : "")>
                            <label for="EditUser_IsActive">
                                <span class="inc"></span>
                                <span class="check"></span>
                                <span class="box"></span>
                                @L("Active")
                            </label>
                        </div>
                        @if (SettingManager.GetSettingValue<bool>(AbpZeroSettingNames.UserManagement.TwoFactorLogin.IsEnabled))
                        {
                            <div class="md-checkbox">
                                <input id="EditUser_IsTwoFactorEnabled" class="md-check" type="checkbox" name="IsTwoFactorEnabled" value="true" @Html.Raw(Model.User.IsTwoFactorEnabled ? "checked=\"checked\"" : "")>
                                <label for="EditUser_IsTwoFactorEnabled">
                                    <span class="inc"></span>
                                    <span class="check"></span>
                                    <span class="box"></span>
                                    @L("IsTwoFactorEnabled")
                                </label>
                            </div>
                        }
                        @if (SettingManager.GetSettingValue<bool>(AbpZeroSettingNames.UserManagement.UserLockOut.IsEnabled))
                        {
                            <div class="md-checkbox">
                                <input id="EditUser_IsLockoutEnabled" class="md-check" type="checkbox" name="IsLockoutEnabled" value="true" @Html.Raw(Model.User.IsLockoutEnabled ? "checked=\"checked\"" : "")>
                                <label for="EditUser_IsLockoutEnabled" data-toggle="tooltip" title="@L("IsLockoutEnabled_Hint")">
                                    <span class="inc"></span>
                                    <span class="check"></span>
                                    <span class="box"></span>
                                    @L("IsLockoutEnabled")
                                </label>
                            </div>
                        }
                    </div>

                </form>

            </div>
            <div class="tab-pane" id="RolesTab">

                <div class="md-checkbox-list user-role-checkbox-list">
                    @foreach (var role in Model.Roles)
                    {
                        <div class="md-checkbox">
                            <input id="EditUser_@(role.RoleName)" class="md-check" type="checkbox" name="@(role.RoleName)" value="true" @Html.Raw(role.IsAssigned ? "checked=\"checked\"" : "")>
                            <label for="EditUser_@(role.RoleName)">
                                <span class="inc"></span>
                                <span class="check"></span>
                                <span class="box"></span>
                                @role.RoleDisplayName
                            </label>
                        </div>
                    }
                </div>

            </div>
        </div>
    </div>

</div>

@Html.Partial("~/Areas/Mpa/Views/Common/Modals/_ModalFooterWithSaveAndCancel.cshtml")
